package com.inmobi.commons.thinICE.icedatacollector;

import android.app.Activity;
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;
import com.inmobi.commons.thinICE.wifi.WifiInfo;
import com.inmobi.commons.thinICE.wifi.WifiUtil;
import java.util.LinkedList;
import java.util.List;

public final class IceDataCollector
{
  private static Context a = null;
  private static ThinICEConfigSettings b = new ThinICEConfigSettings();
  private static Looper c = null;
  private static Handler d = null;
  private static boolean e = false;
  private static Activity f = null;
  private static Runnable g = new b();
  private static LinkedList<Sample> h = new LinkedList();
  private static Sample i = null;
  private static final Object j = new Object();
  private static ThinICEListener k = null;
  private static Runnable l = new a();

  private static final boolean a(ThinICEConfigSettings paramThinICEConfigSettings1, ThinICEConfigSettings paramThinICEConfigSettings2)
  {
    return (paramThinICEConfigSettings1.isEnabled() != paramThinICEConfigSettings2.isEnabled()) || (paramThinICEConfigSettings1.getSampleInterval() != paramThinICEConfigSettings2.getSampleInterval());
  }

  public static void flush()
  {
    try
    {
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "-- flush()");
      synchronized (j)
      {
        i = null;
        h = new LinkedList();
        return;
      }
    }
    finally
    {
    }
  }

  public static ThinICEConfigSettings getConfig()
  {
    return new ThinICEConfigSettings(b);
  }

  public static WifiInfo getConnectedWifiInfo(Context paramContext)
  {
    int m = b.getWifiFlags();
    if (!ThinICEConfigSettings.bitTest(m, 2));
    for (boolean bool1 = true; ; bool1 = false)
    {
      boolean bool2 = ThinICEConfigSettings.bitTest(m, 1);
      boolean bool3 = b.isSampleConnectedWifiEnabled();
      Object localObject = null;
      if (bool3)
      {
        WifiInfo localWifiInfo;
        try
        {
          if (WifiUtil.hasGetConnectedWifiInfoPermission(paramContext))
          {
            localWifiInfo = WifiUtil.getConnectedWifiInfo(paramContext, bool1, bool2);
          }
          else
          {
            if (BuildSettings.DEBUG)
              Log.w("IceDataCollector", "application does not have permission to access connected wifi ap");
            localWifiInfo = null;
          }
        }
        catch (Exception localException)
        {
          boolean bool4 = BuildSettings.DEBUG;
          localObject = null;
          if (!bool4)
            break label108;
        }
        Log.e("IceDataCollector", "Error getting wifi data", localException);
        return null;
        localObject = localWifiInfo;
      }
      label108: return localObject;
    }
  }

  public static List<Sample> getData()
  {
    if (BuildSettings.DEBUG)
      Log.d("IceDataCollector", "-- getData()");
    synchronized (j)
    {
      LinkedList localLinkedList = h;
      flush();
      return localLinkedList;
    }
  }

  public static int getSampleCount()
  {
    synchronized (j)
    {
      int m = h.size();
      return m;
    }
  }

  private static void m()
  {
    if (BuildSettings.DEBUG)
      Log.d("IceDataCollector", "startSampling()");
    if (c != null)
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "ignoring, already sampling");
    do
    {
      return;
      HandlerThread localHandlerThread = new HandlerThread("IDC");
      localHandlerThread.start();
      c = localHandlerThread.getLooper();
      d = new Handler(c);
      d.postDelayed(l, b.getSampleInterval() / 2L);
    }
    while (!BuildSettings.DEBUG);
    Log.d("IceDataCollector", "next sample in " + b.getSampleInterval() / 2L + " ms");
  }

  private static void n()
  {
    if (BuildSettings.DEBUG)
      Log.d("IceDataCollector", "stopSampling()");
    if (c == null)
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "ignoring, not currently sampling");
    do
    {
      return;
      d.removeCallbacks(l);
      d = null;
      c.quit();
      c = null;
    }
    while (!BuildSettings.DEBUG);
    Log.d("IceDataCollector", "sampling stopped");
  }

  // ERROR //
  public static void setConfig(ThinICEConfigSettings paramThinICEConfigSettings)
  {
    // Byte code:
    //   0: ldc 2
    //   2: monitorenter
    //   3: getstatic 95	com/inmobi/commons/thinICE/icedatacollector/BuildSettings:DEBUG	Z
    //   6: ifeq +33 -> 39
    //   9: ldc 97
    //   11: new 189	java/lang/StringBuilder
    //   14: dup
    //   15: invokespecial 190	java/lang/StringBuilder:<init>	()V
    //   18: ldc 223
    //   20: invokevirtual 196	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   23: aload_0
    //   24: invokevirtual 226	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   27: ldc 228
    //   29: invokevirtual 196	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   32: invokevirtual 205	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   35: invokestatic 104	android/util/Log:d	(Ljava/lang/String;Ljava/lang/String;)I
    //   38: pop
    //   39: aload_0
    //   40: ifnonnull +21 -> 61
    //   43: getstatic 95	com/inmobi/commons/thinICE/icedatacollector/BuildSettings:DEBUG	Z
    //   46: ifeq +11 -> 57
    //   49: ldc 97
    //   51: ldc 230
    //   53: invokestatic 104	android/util/Log:d	(Ljava/lang/String;Ljava/lang/String;)I
    //   56: pop
    //   57: ldc 2
    //   59: monitorexit
    //   60: return
    //   61: getstatic 39	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:b	Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;
    //   64: astore_3
    //   65: aload_0
    //   66: putstatic 39	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:b	Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;
    //   69: aload_3
    //   70: invokevirtual 233	com/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings:getSampleHistorySize	()I
    //   73: istore 4
    //   75: getstatic 39	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:b	Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;
    //   78: invokevirtual 233	com/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings:getSampleHistorySize	()I
    //   81: istore 5
    //   83: iload 5
    //   85: iload 4
    //   87: if_icmpge +60 -> 147
    //   90: getstatic 62	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:j	Ljava/lang/Object;
    //   93: astore 6
    //   95: aload 6
    //   97: monitorenter
    //   98: getstatic 57	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:h	Ljava/util/LinkedList;
    //   101: invokevirtual 154	java/util/LinkedList:size	()I
    //   104: iload 5
    //   106: if_icmple +38 -> 144
    //   109: getstatic 95	com/inmobi/commons/thinICE/icedatacollector/BuildSettings:DEBUG	Z
    //   112: ifeq +11 -> 123
    //   115: ldc 97
    //   117: ldc 235
    //   119: invokestatic 104	android/util/Log:d	(Ljava/lang/String;Ljava/lang/String;)I
    //   122: pop
    //   123: getstatic 57	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:h	Ljava/util/LinkedList;
    //   126: iconst_0
    //   127: getstatic 57	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:h	Ljava/util/LinkedList;
    //   130: invokevirtual 154	java/util/LinkedList:size	()I
    //   133: iload 5
    //   135: isub
    //   136: invokevirtual 239	java/util/LinkedList:subList	(II)Ljava/util/List;
    //   139: invokeinterface 244 1 0
    //   144: aload 6
    //   146: monitorexit
    //   147: getstatic 41	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:c	Landroid/os/Looper;
    //   150: ifnonnull +34 -> 184
    //   153: getstatic 95	com/inmobi/commons/thinICE/icedatacollector/BuildSettings:DEBUG	Z
    //   156: ifeq -99 -> 57
    //   159: ldc 97
    //   161: ldc 246
    //   163: invokestatic 104	android/util/Log:d	(Ljava/lang/String;Ljava/lang/String;)I
    //   166: pop
    //   167: goto -110 -> 57
    //   170: astore_1
    //   171: ldc 2
    //   173: monitorexit
    //   174: aload_1
    //   175: athrow
    //   176: astore 7
    //   178: aload 6
    //   180: monitorexit
    //   181: aload 7
    //   183: athrow
    //   184: aload_3
    //   185: getstatic 39	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:b	Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;
    //   188: invokestatic 248	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:a	(Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;)Z
    //   191: ifeq -134 -> 57
    //   194: invokestatic 85	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:n	()V
    //   197: getstatic 39	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:b	Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings;
    //   200: invokevirtual 78	com/inmobi/commons/thinICE/icedatacollector/ThinICEConfigSettings:isEnabled	()Z
    //   203: ifeq +9 -> 212
    //   206: invokestatic 250	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:m	()V
    //   209: goto -152 -> 57
    //   212: invokestatic 150	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:flush	()V
    //   215: aconst_null
    //   216: putstatic 32	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:a	Landroid/content/Context;
    //   219: aconst_null
    //   220: putstatic 47	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:f	Landroid/app/Activity;
    //   223: aconst_null
    //   224: putstatic 64	com/inmobi/commons/thinICE/icedatacollector/IceDataCollector:k	Lcom/inmobi/commons/thinICE/icedatacollector/ThinICEListener;
    //   227: goto -170 -> 57
    //
    // Exception table:
    //   from	to	target	type
    //   3	39	170	finally
    //   43	57	170	finally
    //   61	83	170	finally
    //   90	98	170	finally
    //   147	167	170	finally
    //   181	184	170	finally
    //   184	209	170	finally
    //   212	227	170	finally
    //   98	123	176	finally
    //   123	144	176	finally
    //   144	147	176	finally
    //   178	181	176	finally
  }

  public static void setListener(ThinICEListener paramThinICEListener)
  {
    k = paramThinICEListener;
  }

  public static void start(Context paramContext)
  {
    while (true)
    {
      try
      {
        if (BuildSettings.DEBUG)
          Log.d("IceDataCollector", "-- start()");
        if (paramContext == null)
        {
          if (BuildSettings.DEBUG)
            Log.d("IceDataCollector", "aborting, context is null");
          return;
        }
        if (!b.isEnabled())
        {
          if (!BuildSettings.DEBUG)
            continue;
          Log.d("IceDataCollector", "ignoring, data collection is disabled in settings");
          continue;
        }
      }
      finally
      {
      }
      if (Build.VERSION.SDK_INT < 14)
      {
        if (!(paramContext instanceof Activity))
        {
          if (BuildSettings.DEBUG)
            Log.w("IceDataCollector", "aborting, build < 14 and context is not an activity");
        }
        else
          f = (Activity)paramContext;
      }
      else
      {
        a = paramContext.getApplicationContext();
        m();
        if (e)
        {
          if (BuildSettings.DEBUG)
            Log.d("IceDataCollector", "stop previously requested, clearing request");
          e = false;
          d.removeCallbacks(g);
        }
      }
    }
  }

  public static void stop()
  {
    while (true)
    {
      try
      {
        if (BuildSettings.DEBUG)
          Log.d("IceDataCollector", "-- stop()");
        if (c == null)
        {
          Log.d("IceDataCollector", "ignoring, not currently running");
          return;
        }
        if (e)
        {
          Log.d("IceDataCollector", "ignoring, stop already requested");
          continue;
        }
      }
      finally
      {
      }
      e = true;
      d.postDelayed(g, b.getStopRequestTimeout());
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "stop requested, occurring in " + b.getStopRequestTimeout() + " ms");
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.commons.thinICE.icedatacollector.IceDataCollector
 * JD-Core Version:    0.6.2
 */